<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.pagination.php
 * Type:     function
 * Name:     link
 * Purpose:  zwraca linki do pozostalych stron z danego zakresu
 * Dependencies: function.url.php
 * -------------------------------------------------------------
 */

function smarty_function_paginationO($params, &$smarty) {

	/**
	 * do funkcji nale�y poda� parametry: currPage, pageCount i _value
	 * _value tak jak do smarty_function_url bez uwzgl�dniania strony
	 */
	$class = 'pagination';
	if(isset($params['class'])){
		$class=$params['class'];
		unset($params['class']);
	}
	
	$currPage = $params['currPage'];
	$pageCount = $params['pageCount'];

	if( isset($params['ajax']) )
	{
		$ajax = $params['ajax'];
	}
	unset($params['ajax']);
	unset($params['currPage']);
	unset($params['pageCount']);
	
	if($pageCount <= 1)return '';
	
	
	$ret = '';
//	$params['strona'] = 1;
//	$ret = '<a href="'.smarty_function_url($params,$smarty).'"><<</a> ';

	$params['strona'] = ($currPage > 1?$currPage-1:1);
	$href = (isset($ajax) ? 'onclick=Dosia.Request("' .smarty_function_url($params,$smarty).'") href="#"' :'href="'.smarty_function_url($params,$smarty).'"');
	$ret .= '<div class="floatLeft"><a ' . $href . '><img src="'.URL_STATIC_CONTENT.'/image/buttonProfilZnajomiPoprzednia.gif" alt="" title="" border="0" /></a></div>';
	
	$ret .= '<div class="floatLeft numbers">';
	if($pageCount < 6)for($i = 1; $i <= $pageCount; $i++){

		$params['strona'] = $i;
		if($i != $currPage){
			$href = (isset($ajax) ? 'onclick=Dosia.Request("' .smarty_function_url($params,$smarty).'") href="#"' :'href="'.smarty_function_url($params,$smarty).'"');
			$ret .= '<a ' . $href . '>'.$i.'</a> &nbsp;';
		}else{
			$ret .= $i.' ';
		}
	}else{
		$arr = array();
		if($currPage > 2)$arr[] = $currPage - 2;
		if($currPage > 1)$arr[] = $currPage - 1;
		
		$arr[] = $currPage;
		
		if($currPage < $pageCount)$arr[] = $currPage + 1;
		if($currPage < $pageCount - 1)$arr[] = $currPage + 2;
		
		if($arr[0] > 1)$ret .= '... ';
		foreach($arr AS $k=>$strona){

			$params['strona'] = $strona;
			if($strona != $currPage){
				$href = (isset($ajax) ? 'onclick=Dosia.Request("' .smarty_function_url($params,$smarty).'") href="#"' :'href="'.smarty_function_url($params,$smarty).'"');

				$ret .= '<a ' . $href . '>'.$strona.'</a> &nbsp;'.($k<count($arr)-1?'| ':'');
			}else{
				$ret .= $strona.' '.($k<count($arr)-1?'| ':'');
			}
		}
		if($arr[count($arr)-1] < $pageCount)$ret .= '... ';
		
	}
	$ret .= '</div>';
	
	$params['strona'] = ($currPage < $pageCount?$currPage+1:$pageCount);
	$href = (isset($ajax) ? 'onclick=Dosia.Request("' .smarty_function_url($params,$smarty).'") href="#"' :'href="'.smarty_function_url($params,$smarty).'"');

	$ret .= '<div class="floatRight"><a ' . $href . '>';
	$ret .= '<img src="'.URL_STATIC_CONTENT.'/image/buttonProfilZnajomiNastepna.gif" alt="" title="" border="0" /></a></div>';
	
	
	return '<div class="'.$class.'">'.$ret.'</div> <div class="clearBoth"></div>';
}
?>